<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>黑名单列表</title>
    <link rel="stylesheet" href="${base}/layui/css/layui.css">
    <link rel="stylesheet" href="${base}/awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="${base}/css/formSelects-v4.css">
    <link rel="stylesheet" href="${base}/css/admin.css">
    <style>
    	.layui-bg-black{        width: 200px;height: 136px;margin-right: 30px;float: left;text-align: center;font-size: 33px;color: #000000!important;padding-top: 30px;}
    	.hide {display: none;}
    	.checkbox{display: inline-block;}
    	.layui-form-item{font-size: 18px;}
    	.width100 {width: 100px; margin-right: 30px;float: left;}
    	.width180 {width: 180px; margin-right: 20px;float: left;}
    	.layui-input { display: inline-block; }
    </style>
</head>
<body class="layui-layout-body" style="overflow:scroll;">
<#include "/common/left.flt">	
<div class="layui-main" style="position: absolute;left: 204px;top: 4px; width: calc(100% - 210px);" >
<fieldset class="layui-elem-field layui-field-title" >
  <legend>操作提示</legend>
</fieldset>
<div class="layui-form hide" id="discuss" style="padding-top:20px;padding-right:20px;">
  <div class="layui-form-item layui-form-text">
    <label class="layui-form-label">黑名单词</label>
    <div class="layui-input-block">
      <input name="title" id="title" placeholder="请输入黑名单词" class="layui-input"/>
    </div>
  </div>  
</div>
<blockquote class="layui-elem-quote layui-quote-nm">
 	<button class="layui-btn" id="add"> <span class="fa fa-plus-square-o"></span> 新加</button>
</blockquote> 

<blockquote class="layui-elem-quote layui-quote-nm">
 	<form action="${base}/black_list/index" method="post" id="dataForm" >
        <input type="hidden" id="page" name="page" value="1"/>

        <div class="layui-input-inline" >
        	<input placeholder="模糊查询" name="title" id="title" class="width180 layui-input" value="${title?default('')}" title="模糊查询" />
        	<button class="layui-btn" lay-submit=""> <span class="fa fa-search"></span> 查询</button>
        	
        	<a class="layui-btn" id="del_select"> <span class="fa fa-trash"></span> 删除</a>
 		</div>
    </form>
</blockquote>
<table class="layui-table" >
	<thead>
       <tr>
            <th><input type="checkbox" id="all" />id</th>
            <th>词</th>
            <th>操作</th>
        </tr>
     </thead>
     <tbody>
     <#list page.list as one>
     <tr>
     	<td><input type="checkbox" name="id" value="${one.id}" /> <a onclick="edit(${one.id},'${one.title?default('')}');" >${one.id}</a></td>
     	<td>${one.title?default('')}</td>
     	<td><a onclick="del(${one.id});" ><span class="fa fa-trash"></span></a></td>
     </tr>
     </#list>
     </tbody>
</table>
<div id="pageDiv"></div>
<form action="${base}/util/uploadFile" method="post" name="uploadForm" enctype="multipart/form-data" id="uploadForm" class="hide" >
    <input name="pic" type="file" id="pic" class="hide"/>
</form>
</body>
<script src="${base}/js/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="${base}/layui/layui.all.js"></script>
<script src="https://unpkg.com/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="${base}/js/jquery.form.js"></script>
<script src="${base}/js/formSelects-v4.min.js" type="text/javascript"></script>
<script type="text/javascript">
layui.use('laypage',function () {
    var laypage = layui.laypage ;
    laypage.render({
        elem:"pageDiv",
        count:${page.totalPage*15},
        limit:15,
        curr:${page.pageNumber},
        layout:['count','prev','page','next','skip'],
        jump:function (obj,first) {
            var page = obj.curr;
            if(!first){
                $("#page").val(page);
                $("#dataForm").submit();
            }
        }
    });
});

layui.use('form', function() {
    var form = layui.form;
    form.render('select');
});


$("#del_select").click(function (){
	try {
		var ids = "";
		$('input[name="id"]:checked').each(function(){//遍历每一个名字为interest的复选框，其中选中的执行函数    
			ids = ids + $(this).attr("value")+",";
	    });
		if(ids){
			$.post("${base}/black_list/del_select",
			   		{"ids":ids},function(data){ 
			   			layer.msg(data);
			   			window.location.reload();
			   		}
			    );
		}
     }catch(e) {
        console.log(e)
     }
});
$("#all").click(function (){
	if ($("#all").prop("checked")) {
		$("input[name='id']").prop("checked", true);
	} else {
		$("input[name='id']").prop("checked", false);
	}
});

var formSelects = layui.formSelects;
var id_ = 0;
function edit(id,title){
	id_ = id;
	layui.use('form', function() {
	    var form = layui.form;
	    form.render('select');
	});
	
	$("#title").val(title);
	
	layer.open({
	    type: 1 ,
	    title: '修改黑名单词', 
	    area: ['400px', '240px'],   //宽高
	    shade: 0.4,   //遮罩透明度
	    content: $("#discuss"),
	    btn: ['确定'], //按钮组
	    scrollbar: false ,//屏蔽浏览器滚动条
	    yes: function(index){
	    	var title_1 = $("#title").val();
	    	if (title_1){
	    		$.post("${base}/black_list/save",
				   		{"id":id,"title":title_1},function(data){ 
				   			layer.alert(data);
				   			$("#discuss").hide();
				   			window.location.reload();
				   		}
				 );
	    	}
	        layer.close(index);
	        
	        $("#discuss").hide();
	    },
		cancel: function(){
			$("#discuss").hide();        
	    }
	});
}

$("#add").click(function (){
	layer.open({
	    type: 1 ,
	    title: '新加标签', 
	    area: ['400px', '240px'],   //宽高
	    shade: 0.4,   //遮罩透明度
	    content: $("#discuss"),
	    btn: ['确定'], //按钮组
	    scrollbar: false ,//屏蔽浏览器滚动条
	    yes: function(index){
	    	var title_1 = $("#title").val();
	    	if (title_1){
	    		$.post("${base}/black_list/save",
				   		{"id":0,"title":title_1},function(data){ 
				   			layer.alert(data);
				   			$("#discuss").hide();
				   			window.location.reload();
				   		}
				 );
	    	}
	        layer.close(index);
	        
	        $("#discuss").hide();
	    },
		cancel: function(){
			$("#discuss").hide();        
	    }
	});

});

function del(id){
	//询问框
	layer.confirm('确定要删除吗？', {
	  btn: ['确定'] //按钮
	}, function(){
		$.post("${base}/black_list/del",
		   		{"id":id},function(data){ 
		   			layer.alert(data);
		   			window.location.reload();
		   		}
		    );  
	});
}

</script>
</html>